package com.huahai.controller;

import com.huahai.entity.Order;
import com.huahai.entity.Product;
import com.huahai.service.IOrderService;
import com.huahai.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 测试高并发
 * */
//@RestController
public class OrderController2 {

    @Autowired
    IProductService productService;


    //使用feign
    @GetMapping("/order2/{pid}")
    public Order order(@PathVariable("pid") int id) {
        Order order = new Order();

        //通过fegin调用商品微服务
        Product product = productService.findById(id);

        //模拟网络延时
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        order.setUid(1);
        order.setNumber(99);
        order.setPid(product.getPid());
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        order.setUsername("liyang");

        return order;
    }

    @GetMapping("/order2/message")
    public String message(){
        return "message";
    }
}
